
//
// 20120825 - AH - Created.
// 20120906 - AH - Missing java doc.
//

package org.japril.jhut.swing;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;

import org.japril.jhut.framework.JhutTest;

/**
 * <p>
 *   {@link TreeCellRenderer} for 
 *   {@link JTree} view that shows
 *   {@link JhutTest} hierarchy.
 * </p>
 * @author Arne Halvorsen (AH)
 */
public final class TestTreeCellRenderer implements TreeCellRenderer 
{
  private final DefaultTreeCellRenderer m_dtcr=new DefaultTreeCellRenderer();
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public TestTreeCellRenderer(){}
  
  private final StringBuilder m_sb=new StringBuilder();

  @Override
  public Component getTreeCellRendererComponent(JTree tree, Object value,
    boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
  {
    if (value instanceof JhutTest)
    {
      JhutTest t=(JhutTest)value;
      
      String color="black";
           if (!t.performed()) color="black";
      else if (t.ok())         color="green";
      else                     color="red";
      
      m_sb.setLength(0);
      m_sb.append("<html><font color='").append(color).append("'>")
          .append(t.getName()).append("</font></html>");
           
      return m_dtcr.getTreeCellRendererComponent(tree, m_sb, sel, expanded, 
        leaf, row, hasFocus);
    }
    else
    {
      return m_dtcr.getTreeCellRendererComponent(tree, value, sel, expanded, 
        leaf, row, hasFocus);
    }
  }
  
}
